`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    19:31:09 04/28/2014 
// Design Name: 
// Module Name:    Frame1 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module Frame4(
	output 		reg	[7:0] 	color,		
	input					[10:0]	hcounter, vcounter,										
	input 				clk , clk_5Hz, blank,
/*	input					[1:0] SONG_SELECT, LEVEL_SELECT*/
	input 				S_Song1_1, S_Song2_2, S_Song3_3, S_Turbo_4
				);
	
	parameter	RMh=200, 			RMv=40,	
					ECh=166, 			ECv=80,	
					SELECT_SONGh=220, SELECT_SONGv=140,	
					S1h=230, 			S1v=180,	
					S2h=230, 			S2v=220,
					S3h=230, 			S3v=260,					
					SELECT_Dh=183, 	SELECT_Dv=320,	
					EASYh=282, 			EASYv=360,
					HARDh=284, 			HARDv=400;

					
	
	reg	[2:0]		cc;				
	reg	[1:0]		f;
	reg 	[15:0]	addr;
	
	wire				data;
	
	
	always@(posedge clk_5Hz)										
			begin 
				if(f<3)
					f<=f+1;
				else					
					f<=0;
			end		
		
	
			
	F_ROM_4 U4(clk ,addr, data);	
	
	always@(hcounter, vcounter)
		begin 
			if (blank==0)
				begin
////////////////////////////////Rhythm Master////////////////////////////				
					if (((hcounter-RMh)<244)&&((hcounter-RMh)>=0)&&((vcounter-RMv)<30)&&((vcounter-RMv)>=0))
						begin
							cc<=3'b000;
							addr<=(vcounter-RMv)*244+hcounter-RMh;
						end	
////////////////////////////////EC551 group eagle/////////////////////////				
					else if (((hcounter-ECh)<308)&&((hcounter-ECh)>=0)&&((vcounter-ECv)<30)&&((vcounter-ECv)>=0))
						begin
							cc<=3'b001;
							addr<=(vcounter-ECv)*308+hcounter-ECh+7320;
						end	
////////////////////////////////SELECT SONGS/////////////////////////////				
					else if (((hcounter-SELECT_SONGh)<207)&&((hcounter-SELECT_SONGh)>=0)&&((vcounter-SELECT_SONGv)<20)&&((vcounter-SELECT_SONGv)>=0))
						begin
							cc<=3'b010;
							addr<=(vcounter-SELECT_SONGv)*207+hcounter-SELECT_SONGh+16560;
						end	
////////////////////////////////1.LIANGZHU//////////////////////////////				
					else if (((hcounter-S1h)<185)&&((hcounter-S1h)>=0)&&((vcounter-S1v)<35)&&((vcounter-S1v)>=0))
						begin
							if ((S_Song1_1 == 1) && (S_Song2_2 == 0) && (S_Song3_3 == 0))
								if (f<2)
									begin
										cc<=3'b011;
										addr<=(vcounter-S1v)*185+hcounter-S1h+20700;
									end
								else 
									begin
										cc<=3'b100;
										addr<=(vcounter-S1v)*185+hcounter-S1h+20700;
									end
								else 
									begin
										cc<=3'b011;
										addr<=(vcounter-S1v)*185+hcounter-S1h+20700;
									end
							end
////////////////////////////////2.BELLA/////////////////////////////////				
					else if (((hcounter-S2h)<191)&&((hcounter-S2h)>=0)&&((vcounter-S2v)<35)&&((vcounter-S2v)>=0))
						begin
							if ((S_Song1_1 == 0) && (S_Song2_2 == 1) && (S_Song3_3 == 0))
								if (f<2)
									begin
										cc<=3'b011;
										addr<=(vcounter-S2v)*191+hcounter-S2h+27175;
									end
								else 
									begin
										cc<=3'b100;
										addr<=(vcounter-S2v)*191+hcounter-S2h+27175;
									end
								else 
									begin
										cc<=3'b011;
										addr<=(vcounter-S2v)*191+hcounter-S2h+27175;
									end
							end
////////////////////////////////3.HUG///////////////////////////////////				
					else if (((hcounter-S3h)<114)&&((hcounter-S3h)>=0)&&((vcounter-S3v)<35)&&((vcounter-S3v)>=0))
						begin
							if ((S_Song1_1 == 0) && (S_Song2_2 == 0) && (S_Song3_3 == 1))
								if (f<2)
									begin
										cc<=3'b011;
										addr<=(vcounter-S3v)*114+hcounter-S3h+33860;
									end
								else 
									begin
										cc<=3'b100;
										addr<=(vcounter-S3v)*114+hcounter-S3h+33860;
									end
								else 
									begin
										cc<=3'b011;
										addr<=(vcounter-S3v)*114+hcounter-S3h+33860;
									end
							end		
////////////////////////////////SELECT DIFFICULTY/////////////////////////////				
					else if (((hcounter-SELECT_Dh)<274)&&((hcounter-SELECT_Dh)>=0)&&((vcounter-SELECT_Dv)<20)&&((vcounter-SELECT_Dv)>=0))
						begin
							cc<=3'b010;
							addr<=(vcounter-SELECT_Dv)*274+hcounter-SELECT_Dh+37850;
						end		
////////////////////////////////EASY////////////////////////////////////				
					else if (((hcounter-EASYh)<76)&&((hcounter-EASYh)>=0)&&((vcounter-EASYv)<30)&&((vcounter-EASYv)>=0))
						begin
							if (S_Turbo_4 == 0)
								if (f<2)
									begin
										cc<=3'b011;
										addr<=(vcounter-EASYv)*76+hcounter-EASYh+43330;
									end
								else 
									begin
										cc<=3'b100;
										addr<=(vcounter-EASYv)*76+hcounter-EASYh+43330;
									end
								else 
									begin
										cc<=3'b011;
										addr<=(vcounter-EASYv)*76+hcounter-EASYh+43330;
									end
							end
////////////////////////////////HARD////////////////////////////////////				
					else if (((hcounter-HARDh)<72)&&((hcounter-HARDh)>=0)&&((vcounter-HARDv)<30)&&((vcounter-HARDv)>=0))
						begin
							if (S_Turbo_4 == 1)
								if (f<2)
									begin
										cc<=3'b011;
										addr<=(vcounter-HARDv)*72+hcounter-HARDh+45610;
									end
								else 
									begin
										cc<=3'b100;
										addr<=(vcounter-HARDv)*72+hcounter-HARDh+45610;
									end
								else 
									begin
										cc<=3'b011;
										addr<=(vcounter-HARDv)*72+hcounter-HARDh+45610;
									end
							end												

/////////////////////////////////////////////////////////////////////////	
					else 
						begin
							addr<=0;
						end	
				end
			else
				begin
					addr<=0;
				end
		end
		
		always@(posedge clk)		
			begin
				case (cc)
				3'b000:	
					begin
						color<=data?8'b00000000:8'b11111100;	//rm color
					end
				3'b001:	
					begin
						color<=data?8'b00000000:8'b11110100;	//GROUP color
					end					
				3'b010:	
					begin
						color<=data?8'b00000000:8'b10010111;	//SELECT SONG & DIFF color
					end
				3'b011:	
					begin
						color<=data?8'b00000000:8'b01111001;	//OPTION color
					end
				3'b100:	
					begin
						color<=data?8'b00000000:8'b11111100;	//BLINK color
					end				
				default: color<=8'b00000000;
				endcase
			end	
endmodule






